package cn.example.vip.mall.search.controller;

import cn.example.vip.mall.search.entity.SkuEs;
import cn.example.vip.mall.search.service.SkuSearchService;
import cn.example.vip.mall.util.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/search")
public class SkuSearchController {
	@Autowired
	private SkuSearchService skuSearchService;
	
	/**
	 * 关键词搜索，通过参数接收（常用）
	 * @param
	 * @return
	 */
	@GetMapping
	public RespResult<Map<String, Object>> search(@RequestParam(required = false)Map<String, Object> searchMap,
												  @Autowired HttpServletResponse response) {
		System.out.println("--------" + searchMap);
		Map<String, Object> result = skuSearchService.search(searchMap);
		System.err.println("--------" + result);
		return RespResult.ok(result);
	}
	
	/**
	 * 增加搜索索引
	 * @param skuEs
	 * @return
	 */
	@PostMapping("/add")
	public RespResult add(@RequestBody SkuEs skuEs) {
		skuSearchService.add(skuEs);
		return RespResult.ok();
	}
	
	/**
	 * 删除搜索索引
	 * @param id
	 * @return
	 */
	@DeleteMapping("/del/{id}")
	public RespResult del(@PathVariable String id) {
		skuSearchService.del(id);
		return RespResult.ok();
	}
	
}
